package swta.snippet

import net.liftweb.http.S
import net.liftweb.util.Helpers._
import scala.xml.NodeSeq
import scala.xml.Node
import scala.xml.Group
import scala.xml.Text
import net.liftweb.util.Full

import swta.model.Entry

class EntryManager {
  def addEntry = (new Entry).toForm(
    Full("Post"),
    (t: Entry) => {
      t.save
      S.redirectTo("/view_entries")
    })
  
  def viewEntries(xhtml: Group): NodeSeq = {
    val entries = Entry.findAll

    entries match {
      case Nil => <div>Keine Eintraege gefunden</div>
      
      case entries => entries.flatMap(
        elem => bind("entry", xhtml, "message" -> elem.message.toString))
    }                        
  }
}